<template>
  <el-button type="primary" icon="el-icon-plus" v-bind="$attrs" @click="onClick">
    <slot>新增</slot>
  </el-button>
</template>

<script>
  import { TYPE_ADD } from '../token'
  import { checkUnSetUrlError } from '../utils'

  export default {
    name: 'CrudTableBtnAdd',
    props: {
      url: {
        type: String,
        require: true
      },
      reqEntity: {
        type: Object,
        default: () => ({})
      },
      dialogTitle: {
        type: String,
        default: '新增'
      }
    },
    inject: ['useBridge'],
    methods: {
      onClick() {
        if(this.url) {
          if(!(checkUnSetUrlError(TYPE_ADD, this.url))) return
        }
        this.useBridge('showDialog', {
          type: TYPE_ADD,
          title: this.dialogTitle,
          url: this.url,
          reqEntity: this.reqEntity
        })
      }
    },
  }
</script>

